package com.leetcode;

import com.leetcode.common.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * 141. 环形链表
 * HashSet
 *
 * @author fy
 * @date 2022/4/11 19:28
 */
public class Solution141_1 {

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        Set<ListNode> set = new HashSet<>();
        ListNode cur = head;
        while (cur != null) {
            if (!set.add(cur)) {
                return true;
            }
            cur = cur.next;
        }
        return false;
    }
    
}
